﻿using MediatR;
using Project.Domain.AggregateModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Project.API.Application.Commands
{
    public class CreateProjectCmdHandler
        : IRequestHandler<CreateProjectCmd, Project.Domain.AggregateModels.Project>
    {
        private IProjectRepository _projectRepository;
        public CreateProjectCmdHandler(IProjectRepository projectRepository)
        {
            _projectRepository = projectRepository;
        }
        public async Task<Domain.AggregateModels.Project> Handle(CreateProjectCmd request, CancellationToken cancellationToken)
        {
            await _projectRepository.AddAsync(request.Project);
            await _projectRepository.UnitOfWork.SaveChangesAsync();
            return request.Project;
        }
    }
}
